/*
 * Copyright (C) 拾光分享网 
 * All rights reserved, Designed By www.hiai.top.
 * Email：goodsking@163.com.
 */
package top.hiai.my.favorite;

import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Page;

import top.hiai.common.interceptor.FrontAuthInterceptor;
import top.hiai.common.model.Favorite;
import top.hiai.config.BaseController;

/**
* @Author www.hiai.top
* @Email  goodsking@163.com
* @Message 更多资源尽在www.hiai.top
* @Introduction 类的介绍：个人控制收藏控制器
*/
@Before(FrontAuthInterceptor.class)
public class MyFavoriteController extends BaseController{

	private MyFavoriteService myFavoriteService = new MyFavoriteService();
	
	/**
	 * 遍历该用户文章收藏，分页显示
	 * 
	 */
	public void list(){
        Page<Favorite> favoriteList = myFavoriteService.userArticleFavoritePage(getParaToInt("p", 1),limtCount,getLoginAccountId());
        setAttr("articleCollectList", favoriteList);
        render("articleCollect.html");
        //renderJson();
	}
	
	/**
	 * 遍历该用户收藏的文章分类
	 */
	public void tlist(){
        Page<Favorite> favoriteList = myFavoriteService.userCommentsFavoritePage(getParaToInt("p", 1),limtCount,getLoginAccountId());
        setAttr("CommentsCollectList", favoriteList);
        render("commentsCollect.html");
        //renderJson();
	}
	
	/**
	 * 话题收藏
	 */
	@Clear(FrontAuthInterceptor.class)
	public void commentsFavoriteAdd(){
        if (notLogin()) {
            renderJson(Ret.fail().set("msg", "请先登录"));
            return ;
        }
        Ret ret = myFavoriteService.favoriteAdd(getLoginAccountId(), getPara("refType"), getParaToInt("refId"), getParaToBoolean("isAdd"));
        renderJson(ret);
	}
}